package cn.ytxy.ivos.user.controller;


import cn.ytxy.ivos.base.response.JsonResult;
import cn.ytxy.ivos.user.pojo.dto.UserLoginParam;
import cn.ytxy.ivos.user.pojo.dto.UserQuery;
import cn.ytxy.ivos.user.pojo.dto.UserSaveParam;
import cn.ytxy.ivos.user.pojo.vo.UserVO;
import cn.ytxy.ivos.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author renhong~Deng
 * @Date 2025/4/22 21:25
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("/v1/user/")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("login")
    // @RequestBody 将请求参数封装成UserLoginParam对象
    public JsonResult login(@RequestBody UserLoginParam userLoginParam) {
        log.debug("用户登陆，UserLoginParam={}", userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }


    @PostMapping("save")
    //当前端传过来的数据已经有qs（QueryStirng）转为了查询字符串格式
    //所以不需要使用@RequestBody注解进行映射了
    //public JsonResult saveUser(@RequestBody UserSaveParam userSaveParam){
    public JsonResult saveUser(UserSaveParam userSaveParam) {
        log.debug("保存用户，UserSaveParam={}", userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult select(UserQuery userQuery){
        return JsonResult.ok(userService.selectUser(userQuery));
    }

    @PostMapping("update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("重置密码，userId={}",userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }

    @PostMapping("update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("controller层更新用户状态，userId={},status={}",userId,status);
        userService.updateStatus(userId,status);
        return JsonResult.ok();
    }

    @GetMapping("delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除用户，userId={}",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }

    @GetMapping("/select/audit/{parentId}")
    public JsonResult selectAuditList(@PathVariable Long parentId){
        log.debug("查询审批人列表，parentId={}",parentId);
        List<UserVO> userVOS = userService.selectAuditList(parentId);
        return JsonResult.ok(userVOS);
    }
}
